import { RegularExpression } from '@/common/constVariable';
import { useDescriptionsType } from '@/components/DescriptionsType';
import { Select } from 'antd';
import { useEffect } from 'react';

const getInvisibleUpdateConfig = ({ pageType, record, assetInvisibleForm, mapLoading, assetPurchaseType, assetAcquireType, assetValueType }) => {
  useEffect(() => {
    /** 回填表单 */
    if (pageType === 'view' || pageType === 'edit') {
      assetInvisibleForm?.setFieldsValue({
        ...record.assetjson,
      });
    }
  }, [record]);

  const [invisibleConfig, invisibleMethods] = useDescriptionsType({
    labelWidth: 190,
    basicForm: assetInvisibleForm,
    name: 'accept-assetInvisibleForm',
    schemas: [
      {
        key: 'accept-null',
        title: '',
        fieldChildren: [],
      },
      {
        key: 'accept-info',
        title: '材料信息',
        fieldChildren: [
          {
            field: `ledgerAccount`,
            label: `单位会计科目`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
          // {
          //   field: `quantityOrArea`,
          //   label: `数量`,
          //   component: 'InputNumber',
          //   placeholder: '请输入',
          //   required: true,
          //   disabled: pageType === 'view',
          //   min: 1,
          //   // contentAfter: '份',
          //   pattern: RegularExpression?.number,
          //   patternMsg: '请输入整数',
          // },
          {
            field: `jno`,
            label: `项目代码`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
          {
            field: `procureOrgType`,
            label: `采购组织形式`,
            disabled: pageType === 'view',
            component: 'Render',
            placeholder: '请选择',
            required: true,
            render: (text) => {
              return (
                <Select
                  loading={mapLoading}
                  options={assetPurchaseType}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                  fieldNames={{
                    label: 'name',
                    value: 'id',
                  }}
                />
              );
            },
          },
          {
            field: `obtainType`,
            label: `取得方式`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请选择',
            required: true,
            render: (text) => {
              return (
                <Select
                  loading={mapLoading}
                  options={assetAcquireType}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                  fieldNames={{
                    label: 'name',
                    value: 'id',
                  }}
                />
              );
            },
          },
          {
            field: `obtainDate`,
            label: `取得日期`,
            component: 'DatePicker',
            disabled: pageType === 'view',
            format: 'YYYY-MM-DD',
            placeholder: '请选择',
            required: true,
          },
          {
            field: `operationalDate`,
            label: `投入使用日期`,
            component: 'DatePicker',
            disabled: pageType === 'view',
            format: 'YYYY-MM-DD',
            placeholder: '请选择',
          },
          {
            field: `approvedBy`,
            label: `配置批准单位`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
          {
            field: `valueType`,
            label: `价值类型`,
            disabled: pageType === 'view',
            component: 'Render',
            required: true,
            render: (text) => {
              return (
                <Select
                  loading={mapLoading}
                  options={assetValueType}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                  fieldNames={{
                    label: 'name',
                    value: 'id',
                  }}
                />
              );
            },
          },
          // {
          //   field: `initialAssetValue`,
          //   label: `材料原值`,
          //   component: 'InputNumber',
          //   placeholder: '请输入',
          //   required: true,
          //   disabled: pageType === 'view',
          //   min: 0,
          //   contentAfter: '元',
          //   pattern: RegularExpression?.number,
          //   patternMsg: '请输入整数',
          // },
          {
            field: `fiscalAppropriation`,
            label: `财政拨款`,
            component: 'InputNumber',
            placeholder: '请输入',
            required: true,
            disabled: pageType === 'view',
            min: 0,
            contentAfter: '元',
            pattern: RegularExpression?.number,
            patternMsg: '请输入整数',
          },
          {
            field: `noFiscalAppropriation`,
            label: `非财政拨款`,
            component: 'InputNumber',
            placeholder: '请输入',
            required: true,
            disabled: pageType === 'view',
            min: 0,
            contentAfter: '元',
            pattern: RegularExpression?.number,
            patternMsg: '请输入整数',
          },
          {
            field: `entryState`,
            label: `财务入账状态`,
            component: 'Render',
            disabled: pageType === 'view',
            required: true,
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '未入账',
                      value: 0,
                    },
                    {
                      label: '已入账',
                      value: 1,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `entryDate`,
            label: `记账日期`,
            component: 'DatePicker',
            disabled: pageType === 'view',
            format: 'YYYY-MM-DD',
            placeholder: '请选择',
            required: true,
          },
          {
            field: `entryCode`,
            label: `记账凭证号`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
          {
            field: `financialOfficer`,
            label: `财务负责人`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
          },
          {
            field: `subjectToliability`,
            label: `使用责任主体`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
          {
            field: `forSharing`,
            label: `是否共享共用`,
            component: 'Render',
            disabled: pageType === 'view',
            required: true,
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '是',
                      value: 1,
                    },
                    {
                      label: '否',
                      value: 0,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `isGradeManage`,
            label: `是否分级运维管理`,
            component: 'Render',
            disabled: pageType === 'view',
            required: true,
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '是',
                      value: 1,
                    },
                    {
                      label: '否',
                      value: 0,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `certificateCode`,
            label: `证书编号`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
          },
          {
            field: `createUser`,
            label: `创作人`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
          {
            field: `registrationAuthority`,
            label: `注册登记机关`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
          },
          {
            field: `registerDate`,
            label: `注册日期`,
            component: 'DatePicker',
            disabled: pageType === 'view',
            format: 'YYYY-MM-DD',
            placeholder: '请选择',
          },
          {
            field: `feature`,
            label: `无形资产特征信息`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
          },
          // {
          //   field: `depreciationState`,
          //   label: `折旧/摊销状态`,
          //   disabled: pageType === 'view',
          //   component: 'Input',
          //   placeholder: '请选择',
          //   required: true,
          // },
          // {
          //   field: `depreciationMethod`,
          //   label: `折旧/摊销方法`,
          //   required: true,
          //   disabled: true,
          //   component: 'Input',
          //   placeholder: '请选择',
          //   initialValue: '平均年限法',
          // },
          // {
          //   field: `depreciationYear`,
          //   label: `折旧/摊销年限`,
          //   component: 'InputNumber',
          //   placeholder: '请输入',
          //   disabled: pageType === 'view',
          //   min: 0,
          //   contentAfter: '月',
          //   required: true,
          //   pattern: RegularExpression?.number,
          //   patternMsg: '请输入整数',
          // },
          // {
          //   field: `providedDepreciation`,
          //   label: `已提折旧/摊销月数`,
          //   component: 'InputNumber',
          //   placeholder: '请输入',
          //   disabled: pageType === 'view',
          //   min: 0,
          //   required: true,
          //   // contentAfter: 'm²',
          //   pattern: RegularExpression?.number,
          //   patternMsg: '请输入整数',
          // },
          // {
          //   field: `depreciationMoney`,
          //   label: `累计折旧/摊销`,
          //   component: 'InputNumber',
          //   placeholder: '请输入',
          //   disabled: pageType === 'view',
          //   min: 0,
          //   contentAfter: '元',
          //   required: true,
          //   pattern: RegularExpression?.number,
          //   patternMsg: '请输入整数',
          // },
          {
            field: `denseState`,
            label: `定密状态`,
            component: 'Render',
            disabled: pageType === 'view',
            required: true,
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '未定密',
                      value: 0,
                    },
                    {
                      label: '已定密',
                      value: 1,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `denseDate`,
            label: `定密时间`,
            component: 'DatePicker',
            disabled: pageType === 'view',
            format: 'YYYY-MM-DD',
            placeholder: '请选择',
            required: true,
          },
          {
            field: `longTime`,
            label: `是否长期`,
            component: 'Render',
            disabled: pageType === 'view',
            required: true,
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '是',
                      value: 1,
                    },
                    {
                      label: '否',
                      value: 0,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `secrecyTerm`,
            label: `保密期限`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
        ],
      },
    ],
  });

  return {
    invisibleConfig,
    invisibleMethods,
  };
};

export { getInvisibleUpdateConfig };
